package com.weihuachao.https;


import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.weihuachao.entity.Results;
import com.weihuachao.entity.Work;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Virgo on 2016/7/30.
 */
public abstract class WorkRequestCallBck extends RequestCallBack<String> {

    public WorkRequestCallBck() {
    }

    @Override
    public void onSuccess(ResponseInfo<String> responseInfo) {
        if (responseInfo != null) {
            String json = responseInfo.result;
            Results tmp = JSON.parseObject(json, Results.class);
            List<Work> list = new ArrayList<>();
            if (tmp.getData()!=null) {
                for (int i = 0; i < tmp.getData().size(); ++i) {
                    list.add(tmp.getData().get(i));
                }
                success(list);
            }else {
                XUtils.show("暂时无数据！");
            }

        } else {
            XUtils.show("数据加载失败");
        }
    }

    @Override
    public void onFailure(HttpException e, String s) {
        XUtils.show("网络请求失败");
    }

    public abstract void success(List<Work> data);
}
